import java.util.Scanner;

/**
 * @author vivi
 * @description
 * @date 2024/5/22
 */
public class demo2 {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        char[] s = scanner.next().toCharArray();

        int left = 0, right = 0, len = s.length;
        int count = 0; // 窗口内的字符种类
        int[] hash = new int[26]; // 统计窗⼝内每种字符出现的次数
        int ret = 0; // 结果

        while (right < len) {
            if (hash[s[right] - 'a']++ == 0) {
                count++;
            }
            while (count > 2) {
                if (hash[s[left++] - 'a']-- == 1) {
                    count--;
                }
            }
            ret = Math.max(ret, right - left + 1);
            right++;
        }
        System.out.println(ret);
    }
}
